<!DOCTYPE HTML>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />


    <link href="/static/v5/static/h-ui/css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="/static/v5/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="/static/v5/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link href="/static/v5/static/h-ui.admin/css/H-ui.login.css" rel="stylesheet" type="text/css" />
    <link href="/static/v5/static/h-ui.admin/css/style.css" rel="stylesheet" type="text/css" />
    <link href="/static/v5/lib/Hui-iconfont/1.0.8/iconfont.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="/static/v5/css/jquery.treeview.css">
    <script type="text/javascript" src="/static/v5/lib/jquery/1.9.1/jquery.min.js"></script>
    <script th:src="@{https://code.jquery.com/jquery-latest.js}"></script>
    <script src="/static/v5/js/jquery.treeview.js"></script>
    <script src="/static/v5/js/demo2.2.js"></script>
    <script src="/static/v5/js/jquery.cookie.js"></script>
    <style>
        html{
        }
        *{
            margin: 0px;padding: 0px;
        }
        body{
            font-family: 'Arial';
            font-size: 12px;
        }
        li{

            list-style: none;

        }
        .box{
            width: 160px;
            border: 1px solid lightgray;
            position: relative;
        }
        .san{
            width: 100px;padding: 10px 0px;
            border: 1px solid lightgray;
            color: #999;
            font-size: 12px;
        }
        .san:hover{
            color: black;
        }
        .btn button{
            background: lightblue;
            border: none;
            padding:5px 10px;
            border-radius: 5px;
        }
        .btn{
            position: absolute;
            left: 60px;
            bottom: -50px;
        }
    </style>
    <title>更新角色</title>
</head>
<body>
<nav class="breadcrumb">
    <button type="submit" class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px; margin-left: 5px" onclick="javascript:history.back(-1);" >返回</button>
</nav>
<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-member-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text"  th:value="${role.role_name}" placeholder="" id="role_name" name="role_name">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>状态：</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                <th:block  th:if="${role.is_valid == 0}" >
                    <div class="radio-box">
                        <input name="is_valid" type="radio" id="sex-1" checked="checked"   value="0">
                        <label for="sex-1">可用</label>
                    </div>
                    <div class="radio-box">
                        <input type="radio" id="sex-2" name="is_valid"  value="1">
                        <label for="sex-2">不可用</label>
                    </div>
                </th:block>
                <th:block  th:if="${role.is_valid != 0}" >
                    <div class="radio-box">
                        <input name="is_valid" type="radio" id="sex-1"   value="0">
                        <label for="sex-1">可用</label>
                    </div>
                    <div class="radio-box">
                        <input type="radio" id="sex-2" name="is_valid" checked="checked"   value="1">
                        <label for="sex-2">不可用</label>
                    </div>
                </th:block>

            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>功能：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <div class="box">
                    <ul id="tree" class="filetree">
                        <th:block  th:each="bean: ${functions.obj}">
                            <th:block  th:if="${bean.is_check == 0}" >
                                <li class="menu"><input type="checkbox" th:checked="checked" name="" th:text="${bean.func_name}" th:value="${bean.func_id}">
                            </th:block>
                            <th:block  th:if="${bean.is_check != 0}" >
                                <li class="menu"><input type="checkbox" name="" th:text="${bean.func_name}" th:value="${bean.func_id}">
                            </th:block>

                                <ul  th:if="${bean.is_father} eq '0'">
                                    <th:block  th:each="bean1: ${bean.tsJzFuncions}">
                                        <th:block  th:if="${bean1.is_check == 0}" >
                                            <li class="menu"><input type="checkbox" th:checked="checked" name="" th:text="${bean1.func_name}" th:value="${bean1.func_id}">
                                        </th:block>
                                        <th:block  th:if="${bean1.is_check != 0}" >
                                            <li class="menu"><input type="checkbox" name="" th:text="${bean1.func_name}" th:value="${bean1.func_id}">
                                        </th:block>
                                            <ul  th:if="${bean1.is_father} eq '0'">
                                                <th:block  th:each="bean2: ${bean1.tsJzFuncions}">
                                                    <th:block  th:if="${bean2.is_check == 0}" >
                                                        <li class="menu"><input type="checkbox" th:checked="checked" name="" th:text="${bean2.func_name}" th:value="${bean2.func_id}">
                                                    </th:block>
                                                    <th:block  th:if="${bean2.is_check != 0}" >
                                                        <li class="menu"><input type="checkbox" name="" th:text="${bean2.func_name}" th:value="${bean2.func_id}">
                                                    </th:block>
                                                </th:block>
                                            </ul>
                                        </li>
                                    </th:block>
                                </ul>
                                </th:if>
                            </li>
                        </th:block>

                    </ul>
                </div>
            </div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" id="submit_bt" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>
<!--_footer 作为公共模版分离出去-->


<script type="text/javascript">

    $("#submit_bt").click(function () {

        if(!(/^.{1,16}$/.test($("#role_name").val()))){
            alert("角色名称最多16个字符");
            return;
        }
        if($('input[type=checkbox]:checked').length < 1) {
            alert("最少选择一个功能");
            return;
        }
        var functions = new Array()
        $.each($('input:checkbox:checked'),function(i){
            functions[i] =  parseInt($(this).val());
        });
        /*<![CDATA[*/
        var role_id = [[${role.role_id}]];
        /*]]>*/
        var dataJson = {
            functions:functions,
            role_name:$("#role_name").val() ,
            role_id:role_id,
            is_valid:$('input:radio[name="is_valid"]:checked').val()
        }

        $.ajax({
            type: 'post',
            url: '/v5/admin/role/update'+ "?token="  + sessionStorage.getItem("token") ,
            dataType: 'json',
            data: JSON.stringify(dataJson),
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                if (data.mark == "0") {
                    alert(data.tip)
                } else {
                    alert(data.tip);
                }
            }

        });
    });
</script>
</body>
</html>


